import { Application, Context } from "egg";

/**
 * App生命周期
 */
export default class AppBootHook implements ApplicationLifeCycle {
  app: Application;
  ctx: Context;
  constructor(app: any) {
    this.app = app;
    this.ctx = this.app.createAnonymousContext();
  }

  async configWillLoad() {
    this.ctx.logger.info("配置文件即将加载，这是最后动态修改配置的时机");
  }

  async configDidLoad() {
    this.ctx.logger.info("配置文件加载完成");
  }

  async didLoad() {
    this.ctx.logger.info("文件加载完成");
  }

  async willReady() {
    this.ctx.logger.info("插件启动完毕");
  }

  async didReady() {
    this.ctx.logger.info("worker 准备就绪");
  }

  async serverDidReady() {
    this.ctx.logger.info("应用启动完成");
  }

  async beforeClose() {
    this.ctx.logger.info("应用即将关闭");
  }
}
